package com.koi.common.tree;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author ･ᴗ･
 * @description [TreeNode]
 */
@Data
public class TreeMenu {

    /**
     * 主键ID
     */
    private String id;

    /**
     * 父级parentId
     */
    private String parentId;

    /**
     * Layui 标题
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String label;

    /**
     * Layui 是否路径
     */
    private String href;

    /**
     * Layui 图标
     */
    private String icon;

    /**
     * Layui 是否展开
     */
    private Boolean spread;

    /**
     * Layui 是否外链接
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String target;

    /**
     * Layui 编码
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String typeCode;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    /**
     * ElementUI 标题，根据前端需要字段进行对应
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String name;

    /**
     * 排序码
     */
    private Integer sorted;

    /**
     * 版本号
     */
    private Integer versionNo;

    /**
     * 孩子节点字段
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)  //显示不为空的数据，"child:[]",有这个会显示下拉图标
    private List<TreeMenu> children = new ArrayList<>();

    public TreeMenu() {

    }

    /**
     * @description [构造主页左边的树]
     */
    public TreeMenu(String id, String parentId, String label, String href, String icon, Boolean spread, String target, String typeCode) {
        this.id = id;
        this.parentId = parentId;
        this.label = label;
        this.href = href;
        this.icon = icon;
        this.spread = spread;
        this.target = target;
        this.typeCode = typeCode;
    }

    /**
     * @description [构造前端需要的数据 ElementUI]
     */
    public TreeMenu(String id, String parentId, String typeCode, Date createTime, String name) {
        this.id = id;
        this.parentId = parentId;
        this.typeCode = typeCode;
        this.createTime = createTime;
        this.name = name;
    }

    /**
     * @description [构造前端需要的数据 ElementUI]
     */
    public TreeMenu(String id, String parentId, String typeCode, Date createTime, String name, Integer sorted, Integer versionNo) {
        this.id = id;
        this.parentId = parentId;
        this.typeCode = typeCode;
        this.createTime = createTime;
        this.name = name;
        this.sorted = sorted;
        this.versionNo = versionNo;
    }

}
